<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="模具编码">
              <a-input allow-clear placeholder="请输入模具编号" v-model="queryParam.moldCode"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('模具设计BOM导入EXCEL表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <!-- 分批导入 -->
      <a-button type="primary" style="margin-left: 8px" @click="handleBatchImport">分批导入</a-button>
      <!-- 全部导入 -->
      <a-button type="primary" style="margin-left: 8px" @click="handleAllImport"> 全部导入</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:xWith,y:yHigh}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <!-- 设计BOM-serialNumber-序号 -->
      <div slot="serialNumber" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>

        <!-- 设计BOM-partName-零件名 -->
        <div slot="partName" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>

         <!-- 设计BOM-chineseName中文名 -->
         <div slot="chineseName" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>
        <!-- 设计BOM-englishName英文名 -->
        <div slot="englishName" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>
        <!-- 设计BOM-零件规格 -->
        <div slot="partSpecification" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>
        <!-- 设计BOM-材料 -->
        <div slot="material" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>

        <!-- number-数量 -->
        <div slot="number" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>


        <!-- 设计BOM-备注 -->
        <div slot="remark" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>

        <!-- 设计BOM-模具设计BOM主表id -->
        <div slot="chDesignBomMasterId" slot-scope="text">
          <span style="white-space: pre-line">
            {{ text }}
          </span>
        </div>


        <!-- bom状态插槽 -->
        <template slot="bomStatus" slot-scope="text">
          <a-tag v-if="text == '1'" color="blue">新增</a-tag>
          <a-tag v-if="text == '2'" color="red">变更</a-tag>
          <a-tag v-if="text == '3'" >不变</a-tag>
          <a-tag v-if="text == '4'" color="purple">变更</a-tag>
        </template>

        <!-- 转益模的状态插槽 -->
        <template slot="transferBenefitModelStatus" slot-scope="text">
          <span v-if="text == '1'">未转</span>
          <span v-if="text == '2'">已转</span>
        </template>

        <!-- 是否删除的状态插槽 -->
        <template slot="isDelete" slot-scope="text">
          <a-tag v-if="text == '0'" color="blue">正常</a-tag>
          <a-tag v-if="text == '1'" color="orange">删除</a-tag>
          <!-- <span v-if="text == '0'">正常</span> -->
          <!-- <span v-if="text == '1'">删除</span> -->
          <!-- <span v-if="text == null">null</span> -->
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ch-design-bom-excel-modal ref="modalForm" @ok="modalFormOk"></ch-design-bom-excel-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ChDesignBomExcelModal from './modules/ChDesignBomExcelModal'

  export default {
    name: 'ChDesignBomExcelList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ChDesignBomExcelModal
    },
    data () {
      return {
        xWith: '',
        yHigh: 700,
        description: '模具设计BOM导入EXCEL表管理页面',
        // 表头
        columns: [
          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          // },
          {
            title:'序号',
            width: 60,
            align:"center",
            dataIndex: 'serialNumber',
            scopedSlots: { customRender: 'serialNumber' }
          },
          {
            title:'零件名',
            width: 100,
            align:"center",
            dataIndex: 'partName',
            scopedSlots: { customRender: 'partName' }
          },
          {
            title:'中文名',
            width: 100,
            align:"center",
            dataIndex: 'chineseName',
            scopedSlots: { customRender: 'chineseName' }
          },
          {
            title:'英文名',
            width: 150,
            align:"center",
            dataIndex: 'englishName',
            scopedSlots: { customRender: 'englishName' }
          },
          {
            title:'零件规格',
            width: 200,
            align:"center",
            dataIndex: 'partSpecification',
            scopedSlots: { customRender: 'partSpecification' }
          },
          {
            title:'材料',
            width: 100,
            align:"center",
            dataIndex: 'material',
            scopedSlots: { customRender: 'material' }
          },
          {
            title:'数量',
            width: 70,
            align:"center",
            dataIndex: 'number',
            scopedSlots: { customRender: 'number' }
          },
          {
            title:'备注',
            width: 100,
            align:"center",
            dataIndex: 'remark',
            scopedSlots: { customRender: 'remark' }
          },
          {
            title:'bom状态',
            width: 80,
            align:"center",
            dataIndex: 'bomStatus',
            scopedSlots: { customRender: 'bomStatus' },
          },
          {
            title:'转益模的状态',
            width: 100,
            align:"center",
            dataIndex: 'transferBenefitModelStatus',
            scopedSlots: { customRender: 'transferBenefitModelStatus' },
          },
          {
            title:'是否删除',
            width: 80,
            align:"center",
            dataIndex: 'isDelete',
            scopedSlots: { customRender: 'isDelete' },
          },
          // {
          //   title:'自定义字段1',
          //   align:"center",
          //   dataIndex: 'customFields1String'
          // },
          // {
          //   title:'自定义字段2',
          //   align:"center",
          //   dataIndex: 'customFields2'
          // },
          // {
          //   title:'自定义字段3',
          //   align:"center",
          //   dataIndex: 'customFields3'
          // },
          // {
          //   title:'自定义字段4',
          //   align:"center",
          //   dataIndex: 'customFields4'
          // },
          // {
          //   title:'自定义字段5',
          //   align:"center",
          //   dataIndex: 'customFields5'
          // },
          {
            title:'模具设计BOM主表id',
            // width: 150,
            align:"center",
            dataIndex: 'chDesignBomMasterId',
            scopedSlots: { customRender: 'chDesignBomMasterId' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:150,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/ch/chDesignBomExcel/list",
          delete: "/ch/chDesignBomExcel/delete",
          deleteBatch: "/ch/chDesignBomExcel/deleteBatch",
          exportXlsUrl: "/ch/chDesignBomExcel/exportXls",
          importExcelUrl: "ch/chDesignBomExcel/importExcel",

          // 分批导入
          batchImportExcel:"/ch/chDesignBomExcel/batchImportExcel",
          // 全部导入
          importAllExcel:"/ch/chDesignBomExcel/importAllExcel"
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
       // 计算表格的每列的宽度
    this.columns.map((x, i) => {
      if (x.width) {
        this.xWith = (this.xWith + x.width) * 1
      }
    })
    console.log('this.xWith', this.xWith)
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      // handleBatchImport() {
      //   console.log("imp");
      // },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'serialNumber',text:'序号',dictCode:''})
        fieldList.push({type:'string',value:'partName',text:'零件名',dictCode:''})
        fieldList.push({type:'string',value:'chineseName',text:'中文名',dictCode:''})
        fieldList.push({type:'string',value:'englishName',text:'英文名',dictCode:''})
        fieldList.push({type:'string',value:'partSpecification',text:'零件规格',dictCode:''})
        fieldList.push({type:'string',value:'material',text:'材料',dictCode:''})
        fieldList.push({type:'int',value:'number',text:'数量',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'int',value:'bomStatus',text:'bom状态（1.新增2.变更3.取消）',dictCode:''})
        fieldList.push({type:'int',value:'transferBenefitModelStatus',text:'转益模的状态（1.未转2.已转）',dictCode:''})
        fieldList.push({type:'int',value:'isDelete',text:'是否删除（0.正常1.删除）',dictCode:''})
        fieldList.push({type:'Blob',value:'customFields1',text:'自定义字段1',dictCode:''})
        fieldList.push({type:'Text',value:'customFields2',text:'自定义字段2',dictCode:''})
        fieldList.push({type:'string',value:'customFields3',text:'自定义字段3',dictCode:''})
        fieldList.push({type:'string',value:'customFields4',text:'自定义字段4',dictCode:''})
        fieldList.push({type:'string',value:'customFields5',text:'自定义字段5',dictCode:''})
        fieldList.push({type:'string',value:'chDesignBomMasterId',text:'模具设计BOM主表id',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>